package com.fkcai.hansoul.common.util;

import com.fkcai.hansoul.common.exception.ComFoundException;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;

public class SensitiveWordFilterUtil {
	// 初始化敏感词过滤
	private static final SensitiveWordBs WORD_BS = SensitiveWordBs.newInstance()
			.ignoreCase(true)   // 忽略大小写
			.init();            // 初始化默认敏感词库
	
	
	/**
	 * 过滤敏感词
	 *
	 * @param text 内容
	 */
	public static void filterSensitiveWords(String text) {
		if (WORD_BS.contains(text)) {
			throw new ComFoundException(ResultCode.SENSITIVE_WORD);
		}
	}
	
	
	/**
	 *  替换敏感词为 **
	 * @param text 文本
	 * @return  过滤内容
	 */
	public static String replaceSensitiveWords(String text) {
		return WORD_BS.replace(text);
	}
	
}
